package com.yilin.platform.service.impl.capital;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yilin.platform.base_core.application.PageData;
import com.yilin.platform.base_core.tools.QueryUtil;
import com.yilin.platform.entity.capital.Book;
import com.yilin.platform.entity.user.Account;
import com.yilin.platform.mapper.capital.BookMapper;
import com.yilin.platform.service.capital.IBookService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class BookService extends ServiceImpl<BookMapper, Book> implements IBookService {
  @Resource
    private BookMapper bookMapper;
  @Override
  public void saveBook(Book book, Account account){
    book.setAccouitId(account.getId());
    book.setAccouitName(account.getName());
    bookMapper.insert(book);
  }

  @Override
  public Book getById(String id) {
    return super.getById(id);
  }
  @Override
  public void upditeBook(Book book){
    bookMapper.updateById(book);
  }
  @Override
  public void delBookById(String id){
    bookMapper.deleteById(id);
  }
  @Override
  public PageData<Book> getBookPage(Book query, Integer start, Integer limit) {
    QueryWrapper<Book> queryWrapper = new QueryWrapper<>();
    QueryUtil.andQueryWrapper(queryWrapper, query);
    return page(new PageData<>(start, limit), queryWrapper);
  }
}
